package com.example.ruiji.controller.index;

import com.example.ruiji.service.TagService.TagServiceImpl;
import com.example.ruiji.service.article.ArticleServiceImpl;
import com.example.ruiji.utils.token.MyTokenUtils;
import com.example.ruiji.utils.vo.Result;
import com.example.ruiji.utils.vo.param.PageParam;
import com.example.ruiji.utils.vo.param.TagVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Author:BaiYiChen
 * Date:2022/4/21 20:35
 *
 * @author BaiYiChen
 */
@Controller
public class IndexController {
  @Autowired
  private ArticleServiceImpl articleService;
  @Autowired
  private TagServiceImpl tagService;
  @GetMapping({"/","/index"})
  public String index(Model model, HttpServletRequest req){
    int hotTag=5,hotArticles=3,newArticles=3;
    List<TagVo> hotTags = tagService.getHotTags(hotTag);
    Result article = articleService.hotArticle(hotArticles);
    Result recentlyPublished = articleService.recentlyPublished(newArticles);
    Result archives = articleService.articleArch();
    
    model.addAttribute("hotArticles", article);
    model.addAttribute("tags", hotTags);
    model.addAttribute("newArticles",recentlyPublished);
    model.addAttribute("archives",archives);
    model.addAttribute("user", MyTokenUtils.user);
    System.out.println(MyTokenUtils.user);
    
    return "index";
  }
  
}
